package cn.lyd.base.until;

import org.springframework.context.ApplicationContext;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;


public class SendEmailUtil {
    
    
    public static void send(String text,String to){
        try {
            ApplicationContext context = SpringUtil.getContext();
            JavaMailSender javaMailSender = context.getBean(JavaMailSender.class);
            MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            // 2.发送复杂邮件的工具类
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true,"utf-8");
            helper.setFrom("1064751069@qq.com");
            helper.setSubject("店铺入住审核通知");
            // 3.设置文本内容，第二个参数 true 代表是否是一个html内容
//            helper.setText("<h1>尊敬的vip，恭喜您入住成功，请及时点击下方链接，激活店铺：</h1> " +
//                    "http://localhost:8081/#/registerAgain?shopId="+dto.getShopId(),true);
            helper.setText(text,true);
            // 5.设置收件人
            helper.setTo(to);
            // 6.发送邮件
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}
